<?php
/**
 * @copyright	Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
 * @license		GNU General Public License version 2 or later; see LICENSE.txt
 */

// no direct access
defined('_JEXEC') or die;

/**
 * @package		Joomla.Administrator
 * @subpackage	mod_failedlogins
 * @since		1.6
 */
abstract class modFailedLoginsHelper
{
	/**
	 * Get a list of failed login attempts.
	 *
	 * @param	JObject	The module parameters.
	 * @return	mixed	An array of attempts, or false on error.
	 */
	public static function getList($params)
	{
		// Initialise variables
		$language = JFactory::getLanguage();
		$language->load('mod_failedlogins', JPATH_ADMINISTRATOR, null, true);
		$db = JFactory::getDbo();
		$user = JFactory::getUser();
		$query = $db->getQuery(true);
		//
		$query->select('mla.username, mla.ipaddress, mla.thetime');
		$query->from('#__plg_max_login_attempts AS mla');
		$query->order('mla.thetime DESC');
		$db->setQuery($query, 0, $params->get('count', 5));
		$results = $db->loadObjectList();

		// Check for database errors
		if ($error = $db->getErrorMsg()) {
			JError::raiseError(500, $error);
			return false;
		};

		return $results;
	}
}
